module MC {
	export class MySet {
		public constructor() {
			this.init();
			let info = MC.user.info;
			///console.log(info.id);
		}
		private init() {
			this.loadData();
			this.upView();
		}
		/** 从服务器加载数据 */
		private loadData(){
			MC.api('getNowUserInfo', {shenhe:'true'}, (json: any) => {
				 console.log(json);
				let obj = MC.user.info;
				obj.is_company = json.is_company;
				obj.is_factory = json.is_factory;
				obj.is_yingpin = json.is_yingpin;
				obj.phone = json.phone;

				obj.head = json.head;
				obj.name = json.name;
				obj.id = json.id;
			 	MC.Cache.setObj('user', obj);
				this.upView();

				$('.uppass .tableTitle .title .shenhe').text('正在审核');	
				if(json.is_company_shenhe==MC.DEL.CompanyModel.shenhe_yes){
					$('.is_company_shenhe .shenhe').text('审核通过');
					$('.is_company_shenhe .shenhe').addClass('on');		
				}
				if(json.is_company_shenhe==MC.DEL.CompanyModel.shenhe_jujue){
					$('.is_company_shenhe .shenhe').text('审核拒绝'); 
				}
				if(json.is_company_shenhe==MC.DEL.CompanyModel.shenhe_null){
					$('.is_company_shenhe .shenhe').text('未填写'); 
				}

				if(json.is_factory_shenhe==MC.DEL.CompanyModel.shenhe_yes){
					$('.is_factory_shenhe .shenhe').text('审核通过');
					$('.is_factory_shenhe .shenhe').addClass('on');		
				}
				if(json.is_factory_shenhe==MC.DEL.CompanyModel.shenhe_jujue){
					$('.is_factory_shenhe .shenhe').text('审核拒绝'); 
				}
				if(json.is_factory_shenhe==MC.DEL.CompanyModel.shenhe_null){
					$('.is_factory_shenhe .shenhe').text('未填写'); 
				}

				if(json.is_yingpin_shenhe==MC.DEL.CompanyModel.shenhe_yes){
					$('.is_yingpin_shenhe .shenhe').text('审核通过');
					$('.is_yingpin_shenhe .shenhe').addClass('on');		
				}
				if(json.is_yingpin_shenhe==MC.DEL.CompanyModel.shenhe_jujue){
					$('.is_yingpin_shenhe .shenhe').text('审核拒绝'); 
				}
				if(json.is_yingpin_shenhe==MC.DEL.CompanyModel.shenhe_null){
					$('.is_yingpin_shenhe .shenhe').text('未填写'); 
				}

			});
		}
		/** 刷新视图 */
		private upView() {
			let info = MC.user.info;
			$('#head').attr('src', info.head);
			$('#name').text(info.name);
			$('#phone').text(info.phone);
			$('.orderDockingDiv,.comJobDiv,.yingpinDiv,.fabuhuodan').hide();
			 if (info.is_company) {
				 $('.comJobDiv').show();		//我的招聘
				 $('.fabuhuodan').show();///发布的货单
				//$('.orderDockingDiv').show();///显示我的货单
			} 
			if (info.is_factory) {
			 	$('.comJobDiv').show();		//我的招聘
				$('.orderDockingDiv').show();///显示我的货单
			}
			if (info.is_yingpin) {
				$('.yingpinDiv').show();
			}
			this.upswitch();
		}

		/*** 更新功能开关按钮 */
		private upswitch() {
			let obj = $('.set-switch-div');
			if (!obj[0]) {
				return;
			}
			let info = MC.user.info;
			$(".is_company").prop("checked", info.is_company);
			$(".is_factory").prop("checked", info.is_factory);
			$(".is_yingpin").prop("checked", info.is_yingpin);
		}

		/** 绑定功能页的事件 */
		public bindFunPage() {
			let mthis=this;
			$('.set-switch-div .mui-switch').on('click', function () {
				MC.click(() => {
					let name = $(this).attr('name');
					let obj: any = {};
					MC.apiD('upSwitchFun', {
						name: name,
						value: $(this).prop('checked')
					}, (json: any) => {
						mthis.loadData();
						//console.log(json);
						if(json=='no'){
							MC.msg.alert('没有通过审核,通过审核后才能打开该选项');
						}
					});
				});
			});
		}






	}
}